package com.abhinav.designPatterns.flyweight;

import java.util.HashMap;

public class ShapeFactory {
	private static final HashMap<String, MyShape> shapes = new HashMap<String, MyShape>();

	public static MyShape getShape(String label) {
		MyShape concreteShape = (MyShape) shapes.get(label);
		if (concreteShape == null) {
			if (label.equals("R")) {
				concreteShape = new MyRectangle(label);
				System.out.println("Creating Rectangle");
			} else if (label.equals("O")) {
				concreteShape = new MyOval(label);
				System.out.println("Creating Oval");
			}
			shapes.put(label, concreteShape);
		}
		System.out.println("Container size: "+shapes.size());
		return concreteShape;
	}

}
